<script setup lang="ts">
import {HANDLE_STATUS, PAY_STATUS} from "~/const/common";

definePageMeta({
  title:'代卖域名订单完成',
  layout:'admin',
  keepalive:true,
})

const form=reactive({
  limit:20,
  page:1,
  domain:'',//模糊搜索-域名
});
const {data:list,refresh}=await useServerGet('/backend/agent/orderList',form)
const search=()=>{
  refresh&&refresh();
}
const complete= async (row)=>{
  ElMessageBox.confirm('确定完成订单吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then( async () => {
    const {data,code}=await usePost('/backend/agent/completeOrder',{id:row.id})
    if(code==200){
      refresh&&refresh();
    }
  }).catch(() => {
  });

}
</script>

<template>
  <div>
    <el-card>
      <div class="flex">
        <div class="w-52 mr-2">
          <el-input placeholder="请输入域名" v-model="form.domain" class="w-40" clearable></el-input>
        </div>
        <div class="w-20">
          <el-button type="primary" @click="search">搜索</el-button>
        </div>
      </div>
    </el-card>
    <el-card class="mt-4">
      <el-table :data="list.data.list" stripe :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}" class="h-[620px] overflow-auto">
        <el-table-column prop="domain" label="域名"></el-table-column>
        <el-table-column prop="goods.price" label="代卖价格"></el-table-column>
        <el-table-column prop="money" label="交易价格"></el-table-column>
        <el-table-column prop="fee" label="手续费（元）"></el-table-column>
        <el-table-column prop="created_at" label="交易时间"></el-table-column>
        <el-table-column prop="buy_user_id" label="买家ID"></el-table-column>
        <el-table-column prop="buy_user_phone" label="买家手机号"></el-table-column>
        <el-table-column prop="goods.user_id" label="卖家ID"></el-table-column>
        <el-table-column prop="goods.user_phone" label="卖家手机号"></el-table-column>
        <el-table-column label="支付状态">
          <template #default="{row}">
            {{PAY_STATUS[row.pay_status]}}
          </template>
        </el-table-column>
        <el-table-column  label="状态">
          <template #default="{row}">
            {{HANDLE_STATUS[row.handle_status]}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{row}">
              <el-button type="danger" @click="complete(row)" v-if="!row.handle_status">完成</el-button>
          </template>
        </el-table-column>
      </el-table>
      <MyPage v-model:page="form.page" v-model:perpage="form.limit" v-model:total="list.data.count" @change="refresh"></MyPage>
    </el-card>
  </div>
</template>

<style scoped lang="scss">

</style>